package com.learn.grpc.util;

import io.grpc.EquivalentAddressGroup;

import java.net.InetSocketAddress;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author zongf
 * @since 2023-10-16
 **/
public class AddressUtil {

    public static List<String> getHostPortList(List<EquivalentAddressGroup> serverList) {
        return serverList.stream()
                .map(EquivalentAddressGroup::getAddresses).flatMap(List::stream)
                .map(item -> (InetSocketAddress) item).map(item -> item.getHostName() + ":" + item.getPort())
                .collect(Collectors.toList());
    }
}
